package com.sensePlusVR.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;

import java.io.IOException;
import java.io.InputStream;

/**
 * 通过 路径异步请求网络图片（Bitmap）
 * 
 * @author lhy
 * 
 */
public class BitmapAsyncUtil extends AsyncTask<Integer, Void, Bitmap> {
	private Context context;
	
	public BitmapAsyncUtil(Context context){
		this.context = context;
	}

	@Override
	protected Bitmap doInBackground(Integer... params) {
		InputStream is = context.getResources().openRawResource(params[0]);

		BitmapFactory.Options opts = new BitmapFactory.Options();
		//opts.inSampleSize = 1;
		opts.inPreferredConfig = Bitmap.Config.ARGB_8888;

		Bitmap bitmapTmp;
		try {
			bitmapTmp = BitmapFactory.decodeStream(is, null, opts);
		} finally {
			try {
				is.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		return bitmapTmp;
	}

	@Override
	protected void onPostExecute(Bitmap result) {
		super.onPostExecute(result);
	}
	
	
}